import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


def send_email(msg, file):
    mail_host = 'smtp.163.com'
    mail_user = '15659770110'
    mail_pass = 'GIDRGOOVOURHNAPD'
    sender = '15659770110@163.com'
    receivers = ['memory_d@foxmail.com']

    message = MIMEMultipart()
    message['From'] = sender
    message['To'] = receivers[0]
    message['Subject'] = 'title'

    message.attach(MIMEText('这是菜鸟教程Python 邮件发送测试……', 'plain', 'utf-8'))

    with open(r'C:\TaobaoCheckData\log\wuhuihuang_log_2021-07-30-19-22-23.zip', 'rb')as h:
        content2 = h.read()

    part2 = MIMEText(content2, 'base64', 'utf-8')
    part2['Content-Type'] = 'application/octet-stream'
    part2['Content-Disposition'] = 'attachment;filename="abc.zip"'
    message.attach(part2)

    try:
        smtpObj = smtplib.SMTP()
        smtpObj.connect(mail_host, 25)
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(
            sender, receivers, message.as_string())
        print('success')
        smtpObj.quit()
    except smtplib.SMTPException as e:
        print('error', e)
